package com.czwx.bee.business.manager.modular.main.controller;

import com.czwx.bee.base.common.dto.ResponseDto;
import com.czwx.bee.base.common.exception.BizExceptionEnum;
import com.czwx.bee.business.manager.modular.main.dto.DayLoanMoneyDto;
import com.czwx.bee.business.manager.modular.main.dto.ManageIndexDto;
import com.czwx.bee.business.manager.modular.main.dto.TodayRemindDto;
import com.czwx.bee.business.manager.modular.statistics.model.BizDataModel;
import com.czwx.bee.business.manager.modular.statistics.service.BusinessDataService;
import com.czwx.bee.business.manager.modular.statistics.service.MainIndexService;
import com.czwx.bee.business.manager.modular.sys.model.SecurityUser;
import com.czwx.bee.business.manager.utils.SecurityUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author:wiki
 * @Date:Create in 2018/7/10 0010 下午 1:51
 */
@RestController
@RequestMapping("/main")
@Api(value = "MangeIndexController",tags = "首页及工作台")
public class ManageIndexController {

       @Autowired
       private BusinessDataService businessDataService;

       @Autowired
       private MainIndexService mainIndexService;

       @PostMapping("index")
       @ApiOperation(value = "首页（今日提醒，累计数据，echarts整合接口）", notes = "首页（今日提醒，累计数据，echarts整合接口）", httpMethod = "POST")
       @ApiImplicitParams({
               @ApiImplicitParam(name = "Authorization", value = "请输入凭证", required = true, dataType = "String", paramType = "header")
       })
       @ApiResponses(
               {@ApiResponse(code = 200,response = ManageIndexDto.class,message = "data：中返回list"),
               }
       )
       public ResponseDto index(){
           ResponseDto rs=new ResponseDto(BizExceptionEnum.SUCCESSFUL_OPERATION);
           SecurityUser securityUser=SecurityUtil.getSecurityUser();
           Map map=new HashMap<>();
           BizDataModel bizDataModel=businessDataService.headerTable(new HashMap() {
               {
                   put("drainageId", securityUser.getDrainageId());
                   put("endTime", new Date());
               }
           });
           TodayRemindDto todayRemindDto=mainIndexService.todayRemind(new HashMap() {
               {
                   put("drainageId", securityUser.getDrainageId());
               }
           });
           List<DayLoanMoneyDto> dayLoanMoneyDto=mainIndexService.loanMoneyDay(new HashMap() {
               {
                   put("drainageId", securityUser.getDrainageId());
               }
           });
           String url=mainIndexService.getShopUrl(new HashMap() {
               {
                   put("drainageId", securityUser.getDrainageId());
               }
           });
           ManageIndexDto manageIndexDto=new ManageIndexDto();
           manageIndexDto.setTotalData(bizDataModel);
           manageIndexDto.setTodayRemind(todayRemindDto);
           manageIndexDto.setEcharts(dayLoanMoneyDto);
           manageIndexDto.setUrl(url);
           rs.setData(manageIndexDto);
           return rs;
       }
}
